/**
 * author wen
 * &copy; CUNYU GROUP
 * email wjd_13@hotmail.com
 */
package com.cunyu.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * 二维码维护服务
 * @author win
 * 2019/05/18-17:56
 */
@Service
public class BarCodeService extends BaseService{

    public String groupUrl(String qcode){
        String sql = "select url from barcode where state = 0" ;
        String uper = "update barcode set count = count + 1 where state = 0" ;
        exec(uper) ;
        return getStr(sql);
    }

    @Transactional(rollbackFor = Exception.class)
    public void addUrl(String url,String qcode){
        // 禁用其他
        String uper = "update barcode set state = 1 where state = 0 " ;
        exec(uper) ;

        // 启用新图
        String sql = "insert into barcode ( url, qcode,state) values (?,?,0)" ;
        insert(sql,url,qcode) ;
    }

    public void updateUrl(int id,String url){
        String sql = "update barcode set url = ? where id = ? " ;
        exec(sql,url,id) ;
    }

    public Map<String, Object> useful(){
        String sql = "select * from barcode where state = 0" ;
        return getMap(sql);
    }

}
